package FirstQuestion;

import sun.applet.Main;

/**
 * 编程统计字符串"ABCD123!@#$%ab"中大写字母、小写字母、数字、其它字符的个数并打 印出来。
 * @author cyt
 * @date 2020/6/14
 */
public class FirstQuestion {
    public static void print(String input){
        //初始化各个参数的值
        int countOfUppercaseLetter = 0;
        int countOfLowercaseLetter = 0;
        int countOfDigit = 0;
        int countOfOthers = 0;
        //循环判断每个字符的类型，并且将对应的count+1
        for(int i = 0; i <= input.length() - 1; i++){
            char c = input.charAt(i);
            //判断是否为大写字母
            if(Character.isUpperCase(c)){
                countOfUppercaseLetter++;
            //判断是否为小写字母
            }else if(Character.isLowerCase(c)){
                countOfLowercaseLetter++;
            //判断是否为数字
            }else if(Character.isDigit(c)){
                countOfDigit++;
            //其他字符
            }else {
                countOfOthers++;
            }

        }
        System.out.println("大写字母的个数为："+countOfUppercaseLetter);
        System.out.println("小写字母的个数为："+countOfLowercaseLetter);
        System.out.println("数字的个数为："+countOfDigit);
        System.out.println("其他字符的个数为："+countOfOthers);
    }

}
